<script lang="ts" setup>
import { ref, watch } from "vue"

const props = defineProps(["display"])
const active = ref<boolean>(props.display)

watch(
  () => props.display,
  (nval: boolean) => {
    active.value = nval
  }
)
</script>

<template>
  <div class="um-collapse">
    <div :class="{ 'um-collapse_head': true, 'is-active': active }">
      <slot name="head" />
    </div>
    <transition>
      <div class="um-collapse_wrap" v-if="active">
        <slot />
      </div>
    </transition>
  </div>
</template>

<style lang="scss" scoped>
.um-collapse {
  border-top: 1px solid #ebeef5;
  .um-collapse_head {
    width: 100%;
    padding: 0;
    border: none;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: 48px;
    line-height: 48px;
    background-color: #ffffff;
    color: #303133;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    outline: 0;
    border-bottom: 1px solid #ebeef5;
  }
  .um-collapse_head.is-active {
    border-bottom: none !important;
  }
  .um-collapse_wrap {
    max-height: 1000px;
    will-change: height;
    background-color: #ffffff;
    box-sizing: border-box;
    border-bottom: 1px solid #ebeef5;
    overflow: hidden;
  }
}
</style>
